#include "sprite.h"
#include "stdafx.h"

namespace sprite{

ATOM spriteRegisterClass(HINSTANCE hInstance,WNDPROC WndProc){

	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= NULL;
	wcex.lpszMenuName	= NULL;
	wcex.lpszClassName	= TEXT("sprite");
	wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_ICON2));

	return RegisterClassEx(&wcex);

}

BOOL spriteInitInstance(HINSTANCE hInstance, HWND& hWnd, int nCmdShow, TCHAR* szTitle, HDC& hdc, HGLRC& hrc)
{
   //hInst = hInstance;

   hWnd = CreateWindowEx(NULL,TEXT("sprite"), szTitle, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
      0, 0, 640 , 360 , NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   hdc=GetDC(hWnd);

   
   PIXELFORMATDESCRIPTOR pfd;
   int format=DescribePixelFormat(hdc,0,0,0);
   int i;
   DWORD p=PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_GENERIC_ACCELERATED;
   for(i=1;i<=format;i++){
		DescribePixelFormat(hdc,i,sizeof(pfd),&pfd);
		if(pfd.dwFlags & p){

			if( !pfd.iPixelType ){

				if(pfd.cColorBits==32){

					if(!pfd.cDepthBits){

						break;

					}

				}

			}
		}
   }
   i=7;
   if(SetPixelFormat(hdc,i,0)){
	   hrc=wglCreateContext(hdc);
	   if( wglMakeCurrent(hdc,hrc) )
		   i=1;
   }

   return TRUE;

}

}